package com.ceba.test.base.configs;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import com.ceba.base.helper.LoggerHelper;
import com.ceba.cebautils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class CustomConfig {
	
	private static Logger logger = LoggerFactory.getLogger(CustomConfig.class);
	
	public static String STAMP_PATH = "";
	public static String IMG_WIDTH = "";
	public static String IMG_HEIGHT = "";
	public static String STAMP_X = "";
	public static String STAMP_Y = "";
	public static String MATCH_NAME = "";
	public static String STAMP_PAGE = "";
	public static String STAMP_FLAG = "true";
	
	public static String INERT_TEXT = "";
	
	//上传ftp用户名密码以及存储目录
	public static String FTP_READ_USER = "";
	
	public static String FTP_READ_PWD = "";
	
	public static String FTP_READ_DIR = "";
	
	public static String FTP_WRITE_USER = "";
	
	public static String FTP_WRITE_PWD = "";
	
	public static String FTP_WRITE_DIR = "";
	
	public static String FTP_URL = "";
	
	public static String FTP_PORT = "";
	
	public static String FTP_FILE_NAME = "";
	
	
	public static String FTP_FLAG = "false";
	
	
	public static String CHARSET = "utf-8";
	
	private static void init(Properties props) throws Exception{
		STAMP_PATH = props.getProperty("STAMP_PATH");
		IMG_WIDTH = props.getProperty("IMG_WIDTH");
		IMG_HEIGHT = props.getProperty("IMG_HEIGHT");
		STAMP_X = props.getProperty("STAMP_X");
		STAMP_Y = props.getProperty("STAMP_Y");
		MATCH_NAME = props.getProperty("MATCH_NAME");
		STAMP_PAGE =props.getProperty("STAMP_PAGE");
		if(!StringUtil.isEmptyString(props.getProperty("STAMP_FLAG"))){
			STAMP_FLAG =props.getProperty("STAMP_FLAG") ;
		}
		
		INERT_TEXT = props.getProperty("INERT_TEXT");
		
	}
	
	public static void readSetting(String absolutePath){
		FileInputStream in = null;
		Properties prop = null;
		try {
			in  =  new FileInputStream(absolutePath);
			prop = new Properties();
			prop.load(in);
			init(prop);
		} catch (Exception e) {
			LoggerHelper.error(logger, e,"加载"+absolutePath+"出错");
		} finally{
			if(in !=null){
				try {
					in.close();
				} catch (IOException e) {
					LoggerHelper.error(logger, e,"加载"+absolutePath+"出错");
				}
			}
		}
	}
	/**
	 * 获取一个key的值
	 * @param key 
	 * @return
	 */
	public static String get(String key,String absolutePath) {
		Properties props = new Properties();   
		FileInputStream in = null;
        try {   
            in = new FileInputStream(absolutePath);
            props.load(in);   
            return props.getProperty(key);   
        } catch (Exception e) {   
        	LoggerHelper.error(e, "");
            return "";   
        } finally{
        	if(in !=null){
        		try {
					in.close();
				} catch (IOException e) {
					LoggerHelper.error(e, "");
				}
        	}
        }
	}
	
	
}
